/*
 * AlbumDialog.java
 *
 * Created on October 19, 2008, 9:26 AM
 */
package com.bff.slimserver.musicjukebox.ui;

import com.bff.bjj.utils.Resources.LABEL_KEY;
import com.bff.slimserver.musicjukebox.ui.components.MusicJDialog;
import com.bff.bjj.utils.Utils;
import java.awt.Dimension;
import java.awt.Frame;
import javax.swing.JDialog;
import org.bff.slimserver.musicobjects.SlimArtist;

/**
 *
 * @author  Bill
 */
public class ArtistDialog extends MusicJDialog {

    private SplashScreen sp;
    private SlimArtist artist;

    /** Creates new form AlbumDialog */
    public ArtistDialog(Frame parent, final SlimArtist artist) {
        super(parent);
        this.artist = artist;

        initComponents();
        setTitle(getResource(LABEL_KEY.ARTIST_DIALOG_TITLE, new Object[]{artist.getName()}));
        setSize(new Dimension(750, 500));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnPanel = new com.bff.bjj.ui.component.BJJPanel();
        jButton1 = new javax.swing.JButton();
        songListTablePanel = new SongListTablePanel(false);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jButton1.setText(getResource(LABEL_KEY.DIALOG_CLOSE));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        btnPanel.add(jButton1);

        getContentPane().add(btnPanel, java.awt.BorderLayout.SOUTH);
        getContentPane().add(songListTablePanel, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    dispose();
}//GEN-LAST:event_jButton1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel btnPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel songListTablePanel;
    // End of variables declaration//GEN-END:variables

    @Override
    public void setVisible(boolean b) {
        if (b) {
            final JDialog dialog = this;

            sp = new SplashScreen(Utils.getParentComponent(this), true);
            sp.setIndeterminate(true);
            sp.setTitleLabel(getResource(LABEL_KEY.ARTIST_DIALOG_PROGRESS_TITLE));
            sp.setMainTextArea("\n" + getResource(LABEL_KEY.ARTIST_DIALOG_PROGRESS_TEXT,
                    new Object[]{artist.getName()}) + "\n\n");
            sp.setProgressBarLabel(getResource(LABEL_KEY.ARTIST_DIALOG_PROGRESS_LABEL));
            sp.pack();

            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        getSongListTablePanel().setArtist(artist);
                        dialog.setLocationRelativeTo(getParent());
                        sp.setStopped(true);
                        setDialogVisible(true);
                    } finally {
                        if (!sp.isStopped()) {
                            sp.setStopped(true);
                        }
                    }
                }
            }).start();

        } else {
            super.setVisible(b);
        }
    }

    private void setDialogVisible(boolean b) {
        super.setVisible(b);
    }

    private SongListTablePanel getSongListTablePanel() {
        return (SongListTablePanel) songListTablePanel;
    }
}
